import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

// const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
//   'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='


// 加密
const encryptor = new JSEncrypt()
export function encrypt (txt, publicKey) {
  encryptor.setPublicKey(publicKey) // 设置公钥  
  return encryptor.encrypt(txt)// 对数据进行加密
}

// 前端不做解密
// export function decrypt(txt) {
//   const encryptor = new JSEncrypt()
//   encryptor.setPrivateKey(privateKey) // 设置私钥
//   return encryptor.decrypt(txt) // 对数据进行解密
// }

export function setToken (token) {
  localStorage.setItem('token', JSON.stringify(token))
}

export function getToken () {
  return JSON.parse(localStorage.getItem('token'))
}

export function clearToken () {
  localStorage.removeItem('token')
}